<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/11/25
  Time: 14:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layuicms2.0/layui/css/layui.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layuicms2.0/layui_ext/dtree/dtree.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layuicms2.0/layui_ext/dtree/font/dtreefont.css">
</head>
<body class="childrenBody">
<!-- 搜索条件开始 -->
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>查询条件</legend>
</fieldset>
<form class="layui-form" method="post" id="searchFrm">

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">出租单号:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="rentid" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入出租单号" style="height: 30px;border-radius: 10px">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">身份证号:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="identity" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入身份证号" style="height: 30px;border-radius: 10px">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">车牌号:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="carnumber" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入车牌号" style="height: 30px;border-radius: 10px">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">开始时间:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="startTime" id="startTime" readonly="readonly"
                       class="layui-input layui-input-inline"
                       placeholder="请输入出租开始时间" style="height: 30px;border-radius: 10px">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">结束时间:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="endTime" id="endTime" readonly="readonly"
                       class="layui-input layui-input-inline"
                       placeholder="请输入出租结束时间" style="height: 30px;border-radius: 10px">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">出租单状态:</label>
            <div class="layui-input-inline">
                <input type="radio" name="rentflag" value="0" title="已归还">
                <input type="radio" name="rentflag" value="1" title="未归还">
            </div>
        </div>
    </div>
    <div class="layui-form-item" style="text-align: center">
        <div class="layui-input-black" >
            <button type="button"
                    class="layui-btn layui-btn-normal layui-icon layui-icon-search layui-btn-radius layui-btn-sm"
                    lay-submit  lay-filter="doSearch" style="margin-top: 4px">查询
            </button>
            <button type="reset"
                    class="layui-btn layui-btn-warm layui-icon layui-icon-refresh layui-btn-radius layui-btn-sm"
                    style="margin-top: 4px">重置
            </button>
        </div>
    </div>

</form>
<!-- 搜索条件结束 -->
<table id="rentTable" lay-filter="rentTable"></table>


<script id="barCar" type="text/html">

    <%-- 汽车未归还显示编辑和删除按钮， 如果归还就不显示 --%>
    {{#  if(d.rentflag == 0){ }}
    <a class="layui-btn layui-btn-xs layui-btn-radius" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs layui-btn-radius" lay-event="del">删除</a>
    {{# }else{ }}
    <a class="layui-btn layui-btn-green layui-btn-xs layui-btn-radius" lay-event="exportRent">导出出租单</a>
    {{# } }}

</script>



<!-- 添加和修改的弹出层-->
<div style="display: none;padding: 20px" id="saveOrUpdateDiv">
    <form class="layui-form" lay-filter="dataFrm" id="dataFrm">
        <div class="layui-form-item">
            <label class="layui-form-label">出租单号:</label>
            <div class="layui-input-block">
                <input type="text" name="rentid" lay-verify="required" readonly="readonly" placeholder="请输入出租单号"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">起租时间:</label>
                <div class="layui-input-inline">
                    <input type="text" name="begindate" id="begindate" readonly="readonly" lay-verify="required" placeholder="请输入起租时间" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">还车时间:</label>
                <div class="layui-input-inline">
                    <input type="text" name="returndate1" id="returndate" readonly="readonly"  placeholder="请输入还车时间" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">身份证号:</label>
                <div class="layui-input-inline">
                    <input type="text" name="identity" lay-verify="required" readonly="readonly" placeholder="请输入身份证号"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">车牌号:</label>
                <div class="layui-input-inline">
                    <input type="text" name="carnumber" lay-verify="required" readonly="readonly"  placeholder="请输入车牌号" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">出租价格:</label>
                <div class="layui-input-inline">
                    <input type="text" name="price" lay-verify="required" placeholder="请输入出租价格" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">操作员:</label>
                <div class="layui-input-inline">
                    <input type="text" name="openname" id="openname" lay-verify="required" placeholder="请输入操作员" readonly="readonly" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block" style="text-align: center;padding-right: 120px">
                <button type="button"
                        class="layui-btn layui-btn-normal layui-btn-md layui-icon layui-icon-release layui-btn-radius"
                        lay-filter="doSubmit" lay-submit="">提交
                </button>
                <button type="reset"
                        class="layui-btn layui-btn-warm layui-btn-md layui-icon layui-icon-refresh layui-btn-radius">重置
                </button>
            </div>
        </div>
    </form>
</div>


<script src="${pageContext.request.contextPath}/static/layuicms2.0/layui/layui.js"></script>
    <script>
        var roleTree;
        var rentTable;
        var miniIndex;
        var url;
        var demoTree;
        layui.extend({
            dtree: '${pageContext.request.contextPath}/static/layuicms2.0/layui_ext/dtree/dtree'   // {/}的意思即代表采用自有路径，即不跟随 base 路径
        }).use(['table','form','layer','jquery','dtree','upload'], function(){
            var table = layui.table
            var form = layui.form
            var layer = layui.layer
            var $ = layui.jquery
            var dtree = layui.dtree
            var upload=layui.upload


            // 初始table
            rentTable = table.render({
                elem:"#rentTable"
                ,url:"/car/rent/init"
                ,page: {limit:5 ,limits:[5,10,15]} //开启分页
                ,cellMinWidth:80
                ,cols: [[ //表头
                    {type: 'checkbox', fixed: 'left'}
                    ,{field: 'rentid', title: '出租单号',  fixed: 'center' }
                    ,{field: 'identity', title: '身份证号',   fixed: 'center'}
                    ,{field: 'carnumber', title: '车牌号',  fixed: 'center'}
                    ,{field: 'price', title: '出租价格',   fixed: 'center'}
                    ,{field: 'rentflag', title: '是否出租',  fixed: 'center',templet:function(data) {
                            return data.rentflag == 1 ? "已归还" :"<font color=red >未归还</font>"
                        }}
                    ,{field: 'begindate', title: '起租时间',  fixed: 'center'}
                    ,{field: 'returndate', title: '还车时间',   fixed: 'center'}
                    ,{field: 'openname', title: '操作员',   fixed: 'center'}
                    ,{field: 'createtime', title: '录入时间',   fixed: 'center'}
                    ,{fixed: 'right', title:'操作', toolbar: '#barCar', width:150}
                ]]
            })

            // form表单提交  -- 查询功能
            form.on("submit(doSearch)",function(data) {
                rentTable.reload({
                    url:"/car/rent/init"
                    ,where :data.field
                    ,page:{
                        curr:1
                    }

                })
                return false;
            })


            form.on('submit(doSubmit)', function (data) {
                $.post(url, data.field, function (r) {
                    if (r.code == 0) {
                        layer.close(miniIndex)
                        rentTable.reload({
                            page: {
                                curr: 1
                            }
                        })
                        layer.msg(r.msg, {icon: 1})
                    } else {
                        layer.msg(r.msg, {icon: 2})
                    }
                })
                return false;
            })




            //监听行工具事件
            table.on('tool(rentTable)', function(obj){
                var data = obj.data
                if(obj.event == "edit"){ // 编辑
                    carUpdate(data)


                }else  if(obj.event == "del"){ // 删除
                    del(data)
                } else if(obj.event == "showImg"){
                    layer.open({
                        type:1 // 1（页面层）
                        , title:"【"+data.carnumber+"】的车辆图片"
                        , content:$("#viewCarImageDiv")
                        , area : ['1000px','500px']
                        , success:function(layero, index) {
                            $("#view_carimg").attr("src",data.carimg)
                            $("#view_carimg").show()
                        }

                    })
                }else  if(obj.event=="exportRent"){
                    location.href = "/car/rent/print?rentid="+data.rentid

                }

            })


            function carUpdate(data) {
                miniIndex = layer.open({
                    type: 1
                    , title: "修改菜单"
                    , content: $("#saveOrUpdateDiv")
                    , area: ['750px', '350px']
                    , success: function (layero, index) {
                        form.val("dataFrm", data)
                        url="/car/rent/update"
                    }

                })
            }

            function del(data){
                layer.confirm("您确定要删除该数据吗",function (ind) {
                    $.post("/car/rent/delete",{"rentid":data.rentid},function (r) {
                                layer.msg(r.msg)
                        rentTable.reload()
                    })
                    layer.close(ind)
                })
            }


        });


    </script>
</body>
</html>
